#!/bin/bash
image_name="sys-service"
image_version="1.0.0"
server_port=80
log_path="/data/pt/logs/$image_name"
echo "publish start ..."
#拉取最新代码
echo "1、pull code"
git pull
#编译打包  -am 被依赖的模块也会被编译打包
echo "2、compile and package"
#mvn clean package -Ptest -DskipTests  -am
mvn clean package -Pdev -DskipTests  -am
#停止删除历史容器
echo "3、delete history container"
container_id=$(docker ps | grep $image_name | awk '{print $1}')
if [ ! -n "$container_id" ]; then
  echo "IS NULL"
else
  echo "3.1、stop container"
  docker stop "$container_id"
  echo "3.2、rm container"
  docker rm "$container_id"
fi
#删除历史镜像
echo "4、rm image"
docker rmi bobokunkun/$image_name:$image_version
#创建新的镜像
echo "5、create image"
docker build -t bobokunkun/$image_name:$image_version .
#启动容器
echo "6、start container"
# shellcheck disable=SC2154
docker run -d -p $server_port:$server_port -v "$log_path":"$log_path" bobokunkun/$image_name:$image_version
echo "publish success ..."